﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Model;

namespace BusinnessLogic
{
    public class Userproduct
    {
        public List<Product> PopulateUserproductlist(int userid)
        {
            DataLayer.dluserproduct DLuserproductfiller = new DataLayer.dluserproduct();
            DataSet dts = DLuserproductfiller.UserproductsList(userid);

            List<Product> productlist = new List<Product>();

            
            for (int i = 0; i < dts.Tables[0].Rows.Count; i++)
            {
                string productname = dts.Tables[0].Rows[i]["Name"].ToString();
                int productid = int.Parse(dts.Tables[0].Rows[i]["productId"].ToString());

                Product eenproduct = new Product(productid, productname);
                productlist.Add(eenproduct);

            }
            return productlist;
        }
        public List<Sprint> PopulateSprintlist(int prodid)
        {
            DataLayer.dluserproduct DLsprintfiller = new DataLayer.dluserproduct();
            DataSet dts = DLsprintfiller.SprintList(prodid);

            List<Sprint> sprintlist = new List<Sprint>();

            for (int i = 0; i < dts.Tables[0].Rows.Count; i++)
            {
                // int userids = int.Parse(dts.Tables[0].Rows[i]["UserId"].ToString());
                string naam = dts.Tables[0].Rows[i]["Titel"].ToString();
                int productids = int.Parse(dts.Tables[0].Rows[i]["Sprintid"].ToString());

                Sprint eensprint = new Sprint(productids, naam);
                sprintlist.Add(eensprint);

            }


            return sprintlist;
        }
        public List<UserStory> PopulateUSList(int sprintid)
        {
            DataLayer.dluserproduct DLUserstoryfiller = new DataLayer.dluserproduct();
            DataSet dts = DLUserstoryfiller.USList(sprintid);

            List<UserStory> userstorylist = new List<UserStory>();

            for (int i = 0; i < dts.Tables[0].Rows.Count; i++)
            {
                // int userids = int.Parse(dts.Tables[0].Rows[i]["UserId"].ToString());
                string naam = dts.Tables[0].Rows[i]["Titel"].ToString();
                int sprinttemp = int.Parse(dts.Tables[0].Rows[i]["UserStoryId"].ToString());

                UserStory eenuserstory = new UserStory(naam, sprinttemp);
                userstorylist.Add(eenuserstory);

            }


            return userstorylist;
        }
        public List<Tasks> PopulateTaskList(int usid)
        {

            DataLayer.dluserproduct DLTasksfiller = new DataLayer.dluserproduct();
            DataSet dts = DLTasksfiller.TaskList(usid);

            List<Tasks> taskslist = new List<Tasks>();

            for (int i = 0; i < dts.Tables[0].Rows.Count; i++)
            {
                // int userids = int.Parse(dts.Tables[0].Rows[i]["UserId"].ToString());
                string naam = dts.Tables[0].Rows[i]["Titel"].ToString();
                int ustemp = int.Parse(dts.Tables[0].Rows[i]["TaskId"].ToString());

                Tasks eentask = new Tasks(naam,ustemp);
                taskslist.Add(eentask);

            }


            return taskslist;

        }
    }
}
